package com.buho29.rcmanager.utils;

import java.text.SimpleDateFormat;
import java.util.Date;


public class Format {
	
    public static final String formatSecondsToString(int sg) {
    	
    	Boolean negative = sg<0;
    	
    	sg = Math.abs(sg);
    	
    	int h = (int) sg/3600; 
    	int m = (int)(sg - (h*3600))/60;
    	int s = (int) (sg - (h*3600) - (m*60));
    	
    	String result = String.valueOf(h)+":";
    	
    	if(m<10)result += "0";
    	result+= String.valueOf(m)+":";
    	if(s<10)result += "0";
    	result+= String.valueOf(s);
    	
    	if(negative) result = "-"+result;
    	
        return result; 
    }
    
    public static final String formatDateToString(long sg) {
    	SimpleDateFormat formater = new SimpleDateFormat("dd/MM/yyyy");
        return formater.format(new Date(sg)); 
    }
    
    public static final String formatDecisecondsToString(int sg) {
    	
    	int h = (int) sg/36000; 
    	int m = (int)(sg - (h*36000))/600;
    	int s = (int) (sg - (h*36000) - (m*600))/10;
    	int ds = (int) (sg - (h*36000) - (m*600) - (s*10));
    	
    	
    	String result = String.valueOf(h)+":";
    	
    	if(m<10)result += "0";
    	result+= String.valueOf(m)+":";
    	if(s<10)result += "0";
    	result+= String.valueOf(s)+":";
    	result+= String.valueOf(ds);
    	
        return result; 
    }
    
    public static final int formatStringToSeconds(String str) {
     // Format the current time.
    	
    	String[] time =  str.split(":");
    	int h = Integer.parseInt(time[0]);
    	int m = Integer.parseInt(time[1]);
    	int s = Integer.parseInt(time[2]);
    	
    	
        return h * 3600 + m * 60 + s; 
    }
}
